/*
 * biwire.h
 *
 *  Created on: Apr 7, 2012
 *      Author: eug.krashtan@gmail.com
 */

#ifndef BIWIRE_H_
#define BIWIRE_H_

// Define connections (PORTC only!)
#define BWPORT1 1
#define BWPORT2 2
// Set pin functions
#define ADCPORT BWPORT1
#define GNDPORT BWPORT2

// State for interrupt loop
#define	ADC_SET 0x01
#define	ADC_WAIT 0x02

// LED flashing frequency (in parrots, without small wing)
#define SCAN_FREQ       48
// Work together with SCAN_FREQ to get orange color
#define MAX_COLOR_MIX 50

// Event bits when scan complete
// Main keyboard event indicator - must be cleared after handle
#define BW_EVENT 0x80
// Button pressed
#define BW_EVBT1 0x01
#define BW_EVBT2 0x02
// add additional flags here, like BW_EVBT3=0x04
// EVFIN - event "Indication finished"
#define BW_EVFIN 0x10
// Button released
#define BW_EVOPN 0x20
// If button holds more than BW_LONG_PRESS cycles
#define BW_EVLNG 0x40

// How long we wait for 'LongPress'
#define BW_LONG_PRESS 10

// ADC compare values
#define BW_VBTN1 0x1F
#define BW_VBTN2 0xFE

// Define names for signal array
enum SignalNames {
	LedOff = 0,
	OneGreen = 1,
	OneRed = 2,
	OneOrange = 3,
	TwoGreen = 4,
	TwoRed = 5,
	Alarm = 6,
	OrangeRG = 7
};

// ====== Externals =======
// LED sequence to indicate
extern volatile enum SignalNames BwIndicate;
// Data about button events
extern volatile uint8_t BwButton;
// If not null - delay of led indication, then switch LED off
extern volatile uint8_t BwLedDelay;
// Call on start
void biwire_init(void);

#endif /* BIWIRE_H_ */
